unit ue_grid;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, ComCtrls, ExtCtrls, StdCtrls, Buttons;

type
  TGrid = class(TForm)
    PageControl1: TPageControl;
    TSAt: TTabSheet;
    TSDef: TTabSheet;
    TSTerra: TTabSheet;
    Sg1: TStringGrid;
    uimh: TImage;
    uimv: TImage;
    sg2: TStringGrid;
    uim1h: TImage;
    uim1v: TImage;
    Sgt1: TStringGrid;
    imth: TImage;
    imtv: TImage;
    sgt2: TStringGrid;
    sgt3: TStringGrid;
    imth1: TImage;
    imth2: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    procedure FormCreate(Sender: TObject);
    procedure Sg1GetEditMask(Sender: TObject; ACol, ARow: Integer;
      var Value: String);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure SpeedButton1Click(Sender: TObject);
    procedure updateunits;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Grid: TGrid;

implementation

uses MainUn,ue_def;

{$R *.DFM}


procedure Tgrid.updateunits;
var i:integer;
begin
for i:=1 to 15 do begin
  conf.cfgs[i-1].infantry.a:=strtoint(trimleft(trimright(grid.sg1.cells[1,i])));
  conf.cfgs[i-1].gun.a:=strtoint(trimleft(trimright(grid.sg1.cells[2,i])));
  conf.cfgs[i-1].airgun.a:=strtoint(trimleft(trimright(grid.sg1.cells[3,i])));
  conf.cfgs[i-1].Tank.a:=strtoint(trimleft(trimright(grid.sg1.cells[4,i])));
  conf.cfgs[i-1].supplies.a:=strtoint(trimleft(trimright(grid.sg1.cells[5,i])));
  conf.cfgs[i-1].Fighter.a:=strtoint(trimleft(trimright(grid.sg1.cells[6,i])));
  conf.cfgs[i-1].Bomber.a:=strtoint(trimleft(trimright(grid.sg1.cells[7,i])));
  conf.cfgs[i-1].Submarine.a:=strtoint(trimleft(trimright(grid.sg1.cells[8,i])));
  conf.cfgs[i-1].Transport.a:=strtoint(trimleft(trimright(grid.sg1.cells[9,i])));
  conf.cfgs[i-1].Tanker.a:=strtoint(trimleft(trimright(grid.sg1.cells[10,i])));
  conf.cfgs[i-1].Cruiser.a:=strtoint(trimleft(trimright(grid.sg1.cells[11,i])));
  conf.cfgs[i-1].BattleShip.a:=strtoint(trimleft(trimright(grid.sg1.cells[12,i])));
  conf.cfgs[i-1].Destroyer.a:=strtoint(trimleft(trimright(grid.sg1.cells[13,i])));
  conf.cfgs[i-1].Deminer.a:=strtoint(trimleft(trimright(grid.sg1.cells[14,i])));
  conf.cfgs[i-1].CArrier.a:=strtoint(trimleft(trimright(grid.sg1.cells[15,i])));

  conf.cfgs[i-1].infantry.d:=strtoint(trimleft(trimright(grid.sg2.cells[1,i])));
  conf.cfgs[i-1].gun.d:=strtoint(trimleft(trimright(grid.sg2.cells[2,i])));
  conf.cfgs[i-1].airgun.d:=strtoint(trimleft(trimright(grid.sg2.cells[3,i])));
  conf.cfgs[i-1].Tank.d:=strtoint(trimleft(trimright(grid.sg2.cells[4,i])));
  conf.cfgs[i-1].supplies.d:=strtoint(trimleft(trimright(grid.sg2.cells[5,i])));
  conf.cfgs[i-1].Fighter.d:=strtoint(trimleft(trimright(grid.sg2.cells[6,i])));
  conf.cfgs[i-1].Bomber.d:=strtoint(trimleft(trimright(grid.sg2.cells[7,i])));
  conf.cfgs[i-1].Submarine.d:=strtoint(trimleft(trimright(grid.sg2.cells[8,i])));
  conf.cfgs[i-1].Transport.d:=strtoint(trimleft(trimright(grid.sg2.cells[9,i])));
  conf.cfgs[i-1].Tanker.d:=strtoint(trimleft(trimright(grid.sg2.cells[10,i])));
  conf.cfgs[i-1].Cruiser.d:=strtoint(trimleft(trimright(grid.sg2.cells[11,i])));
  conf.cfgs[i-1].BattleShip.d:=strtoint(trimleft(trimright(grid.sg2.cells[12,i])));
  conf.cfgs[i-1].Destroyer.d:=strtoint(trimleft(trimright(grid.sg2.cells[13,i])));
  conf.cfgs[i-1].Deminer.d:=strtoint(trimleft(trimright(grid.sg2.cells[14,i])));
  conf.cfgs[i-1].CArrier.d:=strtoint(trimleft(trimright(grid.sg2.cells[15,i])));

  conf.cfgs[i-1].forest.a:=strtoint(trimleft(trimright(grid.sgt1.cells[1,i])));
  conf.cfgs[i-1].Mount.a:=strtoint(trimleft(trimright(grid.sgt1.cells[2,i])));
  conf.cfgs[i-1].Desert.a:=strtoint(trimleft(trimright(grid.sgt1.cells[3,i])));
  conf.cfgs[i-1].Arctic.a:=strtoint(trimleft(trimright(grid.sgt1.cells[4,i])));
  conf.cfgs[i-1].Boloto.a:=strtoint(trimleft(trimright(grid.sgt1.cells[5,i])));
  conf.cfgs[i-1].Town.a:=strtoint(trimleft(trimright(grid.sgt1.cells[6,i])));

  conf.cfgs[i-1].forest.d:=strtoint(trimleft(trimright(grid.sgt2.cells[1,i])));
  conf.cfgs[i-1].Mount.d:=strtoint(trimleft(trimright(grid.sgt2.cells[2,i])));
  conf.cfgs[i-1].Desert.d:=strtoint(trimleft(trimright(grid.sgt2.cells[3,i])));
  conf.cfgs[i-1].Arctic.d:=strtoint(trimleft(trimright(grid.sgt2.cells[4,i])));
  conf.cfgs[i-1].Boloto.d:=strtoint(trimleft(trimright(grid.sgt2.cells[5,i])));
  conf.cfgs[i-1].Town.d:=strtoint(trimleft(trimright(grid.sgt2.cells[6,i])));

  conf.cfgs[i-1].forest.v:=strtoint(trimleft(trimright(grid.sgt3.cells[1,i])));
  conf.cfgs[i-1].Mount.v:=strtoint(trimleft(trimright(grid.sgt3.cells[2,i])));
  conf.cfgs[i-1].Desert.v:=strtoint(trimleft(trimright(grid.sgt3.cells[3,i])));
  conf.cfgs[i-1].Arctic.v:=strtoint(trimleft(trimright(grid.sgt3.cells[4,i])));
  conf.cfgs[i-1].Boloto.v:=strtoint(trimleft(trimright(grid.sgt3.cells[5,i])));
  conf.cfgs[i-1].Town.v:=strtoint(trimleft(trimright(grid.sgt3.cells[6,i])));

 end;
end;

procedure TGrid.FormCreate(Sender: TObject);
var
 i:integer;
begin
  for i:=0 to 14 do begin
   sg1.Cells[0,i+1]:=inttostr(i+1);
   sg1.cells[i+1,0]:=inttostr(i+1);
   sg2.Cells[0,i+1]:=inttostr(i+1);
   sg2.cells[i+1,0]:=inttostr(i+1);
   sgt2.Cells[0,i+1]:=inttostr(i+1);
   sgt1.Cells[0,i+1]:=inttostr(i+1);
   sgt3.Cells[0,i+1]:=inttostr(i+1);
  end;
  uimh.canvas.brush.color:=clbtnface;
  uimh.canvas.FillRect(rect(0,0,435,29));
  imtv.canvas.brush.color:=clbtnface;
  imtv.canvas.FillRect(rect(0,0,29,435));
  imth.canvas.brush.color:=clbtnface;
  imth.canvas.FillRect(rect(0,0,194,29));
  imth1.canvas.brush.color:=clbtnface;
  imth1.canvas.FillRect(rect(0,0,194,29));
  imth2.canvas.brush.color:=clbtnface;
  imth2.canvas.FillRect(rect(0,0,194,29));
  uimv.canvas.brush.color:=clbtnface;
  uimv.canvas.FillRect(rect(0,0,29,435));
  uim1h.canvas.brush.color:=clbtnface;
  uim1h.canvas.FillRect(rect(0,0,435,29));
  uim1v.canvas.brush.color:=clbtnface;
  uim1v.canvas.FillRect(rect(0,0,29,435));
  fuedit.il1.draw(imth.canvas,0,0,68);
  fuedit.il1.draw(imth.canvas,29,0,106);
  fuedit.il1.draw(imth.canvas,58,0,46);
  fuedit.il1.draw(imth.canvas,58+29,0,85);
  fuedit.il1.draw(imth.canvas,58+58,0,1);
  fuedit.il1.draw(imth.canvas,58+58,0,110);
  fuedit.il1.draw(imth.canvas,58+58+29,0,103);
  fuedit.il1.draw(imth1.canvas,0,0,68);
  fuedit.il1.draw(imth1.canvas,29,0,106);
  fuedit.il1.draw(imth1.canvas,58,0,46);
  fuedit.il1.draw(imth1.canvas,58+29,0,85);
  fuedit.il1.draw(imth1.canvas,58+58,0,1);
  fuedit.il1.draw(imth1.canvas,58+58,0,110);
  fuedit.il1.draw(imth1.canvas,58+58+29,0,103);
  fuedit.il1.draw(imth2.canvas,0,0,68);
  fuedit.il1.draw(imth2.canvas,29,0,106);
  fuedit.il1.draw(imth2.canvas,58,0,46);
  fuedit.il1.draw(imth2.canvas,58+29,0,85);
  fuedit.il1.draw(imth2.canvas,58+58,0,1);
  fuedit.il1.draw(imth2.canvas,58+58,0,110);
  fuedit.il1.draw(imth2.canvas,58+58+29,0,103);
  for i:=0 to 14 do begin
   fuedit.Ul1.draw(uimh.canvas,i*29,0,i);
   fuedit.Ul1.draw(uimv.canvas,0,i*29,i);
   fuedit.Ul1.draw(uim1h.canvas,i*29,0,i);
   fuedit.Ul1.draw(uim1v.canvas,0,i*29,i);
   fuedit.Ul1.draw(imtv.canvas,0,i*29,i);
  end;
   uimh.Refresh;
  PageControl1.ActivePage:=TSat;
end;

procedure TGrid.Sg1GetEditMask(Sender: TObject; ACol, ARow: Integer;
  var Value: String);
begin
 value:='###';
end;

procedure TGrid.FormClose(Sender: TObject; var Action: TCloseAction);
var
 i:integer;
begin
 updateunits;
end;

procedure TGrid.SpeedButton1Click(Sender: TObject);
begin
     updateunits;
     conf.SaveToFile('armies.dat');
end;

end.
